package com.example.fw;

import java.util.Collection;
import java.util.HashSet;

import java.util.Set;

public class Groups {
	
	private Set<GroupObject> storredGroups = null;
	
	public Groups (Collection<GroupObject> groups) {
		storredGroups = new HashSet<GroupObject>(groups);
	}
	public Groups withAdded(GroupObject group) {
		Groups groups2 = new Groups(storredGroups);
		group.setId("$$$");
		groups2.storredGroups.add(group);
		group.setId(null);
		return groups2;
	}
	//lastGroupId = lastGroupId+1;
	//groupObject.setId("" +lastGroupId);

	public Groups withoutRemoved(GroupObject group) {
		Groups groups2 = new Groups(storredGroups);
		groups2.storredGroups.remove(group);
		return groups2;
	}
//	public Groups withModified(GroupObject group) {
//		Groups groups2 = new Groups(storredGroups);
//		groups2.storredGroups.remove(group);
//		group.setId("$$$");
//		groups2.storredGroups.add(group);
//		group.setId(null);
//		return groups2;
//	}
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((storredGroups == null) ? 0 : storredGroups.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Groups other = (Groups) obj;
		if (storredGroups == null) {
			if (other.storredGroups != null) {
				return false;
			}
		} else if (!storredGroups.equals(other.storredGroups)) {
			return false;
		}
		return true;
	}

	public GroupObject getSomeGroup() {
		return storredGroups.iterator().next();
}
	@Override
	public String toString() {
		return "Groups [storredGroups=" + storredGroups + "]";
	}
	
}
